package com.shuwang.jh_shop.ui.activity
import android.os.Build
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.shuwang.jh_shop.R
import com.shuwang.jh_shop.ui.activity.MainTab
import com.shuwang.jh_shop.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_main
    }
    override fun initView() {
        tabhost.setup(this,supportFragmentManager, R.id.realtabcontent)
        tabhost.tabWidget.dividerDrawable=null
        var tabs = MainTab.values()
        for (item in tabs){
            val tabSpec = tabhost.newTabSpec(item.name)
            val indicator = View.inflate(this, R.layout.tab_indicator,null)
            val title = indicator.findViewById(R.id.tab_title) as TextView
            val icon = indicator.findViewById(R.id.iv_user_flow_icon) as ImageView
            val drawable = this.resources.getDrawable(item.resIcon)
            title.text = getString(item.resName)
            icon.setImageDrawable(drawable)
            tabSpec.setIndicator(indicator)
            tabhost.addTab(tabSpec, item.clz,null)
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        tabhost.setOnTabChangedListener{
           tid -> kotlin.run {
                if (tid.equals("ME")){
                    window.statusBarColor= ContextCompat.getColor(applicationContext, R.color.colorAccent)
                }else{
                    window.statusBarColor= ContextCompat.getColor(applicationContext, R.color.colorPrimary)
                }
            }
        }
    }
    override fun initData() {
    }


}
